<h2><%=h _("Issue: ")%><%=h @issue.subject %> </h2>

<% if logged_in? && (comment_count = self.current_user.comments.count(:conditions => ['comments.issue_id = ? and draft = 1', @issue.id])) && comment_count != 0 %>
<div class="error">You have <b><%=h comment_count %> draft</b>
 comments.
Drafts are not viewable by others; use
<%= link_to _("Publish+Mail Comments"), {:controller => :issue, :action => :publish, :id => @issue.id}, :class => 'novisit' %>
 to let others view them.
</div>
<% end %>

<div style="float: left; padding-right: 1em">
<div>
  <i><%=h _("Created:")%></i> <%=h _("%{timeago} by %{user}") % {:timeago => timeago(@issue.created_at), :user => (logged_in? && @issue.user_id == self.current_user.id) ? _("me") : @issue.user.login} %>
  <i><%=h _("Last updated:")%></i> <%=h timeago @issue.updated_at %>
</div>
<div><i><%=h _("SVN Base:") %></i> <%=h @issue.repo_url %></div>

<div><i><%=h _("Reviewers:")%></i> <%=h @issue.reviewer_string %></div>
<div>
  <%= link_to _("Edit Issue"), {:controller => :issue, :action => :edit, :id => @issue.id}, :class => 'novisit' %>
  
  |
  
  <%= link_to _("Publish+Mail Comments"), {:controller => :issue, :action => :publish, :id => @issue.id}, :class => 'novisit' %>
  
  |
  <% if @issue.patchsets.first %>
    <strong><%= link_to _("Start Review"), {:controller => :issue, :action => :diff, :id => @issue.id, :psid => @issue.patchsets.first.id, :pid => @issue.patchsets.first.patches.first.id}, :class => 'novisit' %></strong>
  <% end %>
</div>
</div>

<% if @issue.description %>
<div style="float: left"><i>Description:</i>
<pre style="background-color: #e5ecf9; margin-top: 0; padding: 3px; overflow: auto">
<%=h @issue.description %>
</pre>
</div>
<% end %>
<div style="clear:both"></div>

<% i = 0 %>
<% patchsets = @issue.patchsets %>
<% @issue.patchsets.each {|ps| %>
  <% i += 1 %>
  <h3>
    <a id="ps-<%= ps.id %>-pointer"
       href="javascript:M_toggleSection('ps-<%= ps.id %>')"
       class="toggled-section">
      <%=h _("Patch Set %{number}") % {:number => i} %>:<%=h ps.message %>
    </a>
  </h3>

  <div>
    <i><%=h _("Total comments:")%></i> <%= ps.comment_count.to_i %>
    <div id="ps-<%= ps.id %>" style="display:none"></div>
    <i><%=h _("Created:")%></i> <%=h timeago ps.created_at %>
  </div>
  <div>
    <%= link_to _("Download raw patch set"), :controller => :issue, :action => :download, :id => @issue.id, :psid => ps.id %>
  </div>
  <table id="queues">
    <tr>
      <th><%=h _("Raw unified diffs")%></th>
      <th colspan="2"><%=h _("Stats")%></th>
      <th><%=h _("Side-by-side diffs with inline comments")%></th>
    </tr>
    <% ps.patches.each {|p| %>
      <tr>
	<td>
	  <%= link_to p.filename,{:controller => :issue, :action => :patch, :id => @issue.id, :psid => ps.id, :pid => p.id}, :class => "noul" %>
	</td>
	<td><%= n_("%{chunk} chunk", "%{chunk} chunks", p.chunk) % {:chunk => p.chunk} %></td>
	<% line = p.text.split(/\r\n|\r|\n/).size %>
	<td><%= n_("%{line} line", "%{line} lines", line) % {:line => line} %></td>
	<td>
	  <b>
	      <%= link_to n_("%{count} comment", "%{count} comments", p.comment_count.to_i) % {:count => p.comment_count.to_i}, {:controller => :issue, :action => :diff, :id => @issue.id, :psid => ps.id, :pid => p.id}, :class => "noul" %>
	      <% if p.draft_comment(self.current_user) && p.draft_comment(self.current_user) != 0 %>
	        <span style="color:red">+ <%= p.draft_comment self.current_user %> drafts</span>
	      <% end %>
	  </b>
	</td>
	<td>
	  <% if patchsets.size > 1 %>
	  <% j = 0 %>
	    <% patchsets.each {|tmp| 
	       j += 1
	       next if tmp.id == ps.id
	    %>
	      <%= link_to _("delta from patch set %{set}") % {:set => j}, :controller => :issue, :action => :diff2, :id => @issue.id, :psid => "#{ps.id}:#{tmp.id}", :pid => p.id %> 
	    <% } %>
	  <% end %>
	</td>
      </tr>
    <% } %>
  </table>
</div>

<% } %>

<h3>
<a id="add-pointer"
   href="javascript:M_toggleSection('add')"
   class="toggled-section">
<%= _("Add Another Patch Set") %></a>
</h3>

<% form_tag({:controller => :issue, :action => :add, :id => @issue.id}, :multipart => true, :method => "post", :id => "add", :style => "display:none") do %>
  <table>
    <tr>
      <th>
	<label for="id_message">Message:</label>
      </th>
      <td>
	<%= text_field :patchset, :message, :size => 60, :maxlength => 100 %>
      </td>
    </tr>
    <tr>
      <th>
	<label for="id_data">Data:</label>
      </th>
      <td>
	<%= file_field :patchset, :data %>
      </td>
    </tr>
    <tr>
      <th><label for="id_url">Url:</label></th>
      <td>
	<%= text_field :patchset, :url, :size => 60, :maxlength => 2083 %>
      </td>
    </tr>
    <tr>
      <td>
	<%= submit_tag _("Add Patch Set") %>
      </td>
      <td>
	You can also add a patch set to this issue using
	<code>upload.py -i <%= @issue.id %></code>
      </td>
    </tr>
  </table>
<% end %>


<h2>Messages</h2>

<a href="javascript:M_showAllComments('cl', 10)">
Expand All Comments</a>
|
<a href="javascript:M_hideAllComments('cl', 10)">
Collapse All Comments</a>

<% @issue.messages.each {|m|%>
  <div class="comment_title" onclick="M_switchChangelistComment(<%= m.id %>)">
    From: <%= (logged_in? && m.user_id == self.current_user.id) ? "me" : m.user.login %>
    <span id="cl-preview-<%= m.id %>" class="extra">
      <%= timeago m.created_at %>
    </span>
  </div>
  <div id="cl-comment-<%= m.id %>" style="display: none;">
    <div>Subject: <%=h m.subject %></div>
    <div>To: <%= m.reviewer_string %></div>
    <div>Date: <%= m.created_at %></div>
    <pre><%= trans m.message %></pre>
  </div>
<% } %>


<div style="border-top: thin solid;"></div>

<a href="javascript:M_showAllComments('cl', 10)">
Expand All Comments</a>
|
<a href="javascript:M_hideAllComments('cl', 10)">
Collapse All Comments</a>

<script language="JavaScript" type="text/javascript"><!--
document.onkeypress = function(evt) { return M_changelistKeyPress(evt); }
// -->
</script>
